from . import blue_app
from flask import request,jsonify
from ..tool.myTool import domain
from spider.news import news_list
from spider import news_sp

@blue_app.route("/slideshow/get",methods=["GET","POST"])
@domain
def getSlideshow():
    result = [
        {
            "id":1,
            "url":"xxx",
            "img":"https://chy-public-1257482107.cos.ap-guangzhou.myqcloud.com/8b8dc47c-b402-11e8-bfc7-acde48001122",
        },
        {
            "id": 2,
            "url": "xxx2",
            "img": "https://chy-public-1257482107.cos.ap-guangzhou.myqcloud.com/4a103d92-ba68-11e8-91a5-acde48001122",
        },
        {
            "id": 3,
            "url": "xxx3",
            "img": "https://chy-public-1257482107.cos.ap-guangzhou.myqcloud.com/645b313e-ba68-11e8-91a5-acde48001122",
        },
    ]
    return result


@blue_app.route("/news/get",methods=["get"])
@domain
def getNewsLimt():
    start = request.args.get("start")
    end = request.args.get("end")
    return news_list[int(start):int(end)]

@blue_app.route("/news/detail/<int:id>",methods=["get"])
@domain
def getNewDetail(id):
    result = news_sp.getNewsDetail(id)
    return result

@blue_app.route("/news/comment/<int:id>",methods=["get"])
@domain
def getComment(id):
    start = request.args.get("start",None)
    end = request.args.get("end",None)
    if not all([start,end]):
        return {"msg":"参数异常"}
    start_int= int(start)
    end_int = int(end)
    result = news_sp.getNewsComment(id,start_int,end_int)
    return result

@blue_app.route("/news/save",methods=["post"])
@domain
def saveComment():
    id = request.form.get("id")
    context = request.form.get("context")
    result = news_sp.setNewsComment(id,None,context)
    return result
